| Muhammad Hassan
Try-Catch-Finally is a concept that is used to handle different exceptions. A Try-Catch statement usually contains a Try block and a Catch block with Finally block as optional. The Try block contains all the actual tasks to be performed while the Catch block is only executed when an exception occurs while executing the Try block and at the end the Finally block gets executed. This concept is widely used by software engineers for handling different types of exeptions.
Power Automate Developers also need to implement the Try-Catch-Finally in flows as there’s great probability of errors and exceptions to be thrown while the flow is being executed. Unfortunately there’s no out of the box feature or action to achieve that. But there’s a work around for that. In the article we will be demonstrating on that.
To get started login to your Power Automate account and head over to ‘my flows’ and create a new flow. For our example we will be creating an instant flow.
Now give this a name and select Manual trigger as the trigger.
Now let’s add three scopes and name them as Try, Catch and Finally. Scope is also an action and can easily be added by clicking on ‘New Step’ and searching scope. Scope is used to group actions so we will leverage it to group actions accordingly.
The important thing here is to make sure that the Catch block gets executed only when the Try block throws exception and the Finally block gets executed whatsoever. To achieve that we’ll have to configure run after for the Catch and Finally block as follows.
That’s all we need to do. Now let’s test this flow. First I’ll cause exception in the Try block and Second there will be no exception in the Try block.
In the above example an exception was caused in the Try block therefore the flow jumped straight to the Catch block.
And in the example above no exceptions were cause therefore the Catch block was skipped and only Finally block is executed.
Join us next time, as we continue our journey of learning canvas apps.Click here to learn more about Imperium's Power Apps Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.